package com.ruoyi.web.controller.wind;


import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.system.service.ISysDictTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * <p>
 *  大气风场通用接口集合
 * </p>
 *
 * @author liuhl
 * @since 2024-04-15
 */
@RestController
@RequestMapping("/common/wind")
@AllArgsConstructor
@Slf4j
@Api(tags = "大气风场通用接口集合")
public class WindCommonController {

    private ISysDictTypeService dictTypeService;


    @GetMapping("/sates")
    @ApiOperation(value = "获取卫星列表", notes = "获取风场相关卫星列表", httpMethod = "GET")
    public AjaxResult getSates() {
        //天基-大气风场卫星 type=air_wind_satellite
        //再分析数据 type=reanalysis_type
        List<SysDictData> airWindSatelliteList = dictTypeService.selectDictDataByType("air_wind_satellite");
        List<SysDictData> reanalysisTypeList = dictTypeService.selectDictDataByType("reanalysis_type");
        List<SysDictData> list = new ArrayList<>();
        list.addAll(airWindSatelliteList);
        list.addAll(reanalysisTypeList);

        List<Map<String, String>> dictAllList = new ArrayList<>();

        if (CollUtil.isNotEmpty(list)){
            List<Map<String, String>> dictMapList = list.stream().map(o -> {
                return MapUtil.builder(new HashMap<String, String>())
                        .put("label", o.getDictLabel())
                        .put("value", o.getDictValue())
                        .build();
            }).collect(Collectors.toList());
            dictAllList.addAll(dictMapList);
        }
        Map<String, String> soundingMap = MapUtil.builder(new HashMap<String, String>())
                .put("label", "Sounding")
                .put("value", "Sounding")
                .build();
        dictAllList.add(soundingMap);
        return AjaxResult.success(dictAllList);
    }


}
